#include "Alice/Math/Vec2.h"
#include <iostream>

namespace Alice
{

float Vec2::CalLength(const Vec2& vec)
{
	return sqrt(vec.x*vec.x + vec.y*vec.y);
}

Vec2 Vec2::CalRotateDot(const Vec2& dot, const Vec2& center, float angle)
{
	float rad = angle / 180.0f * PI;
	float _cos;
	float _sin;

	_cos = cos(rad);
	_sin = sin(rad);

	float x = 
		(dot.x - center.x) * _cos -
		(dot.y - center.y) * _sin + center.x;
	float y =
		(dot.x - center.x) * _sin +
		(dot.y - center.y) * _cos + center.y;

	return Vec2{x, y};
}

float Vec2::CalZeta(const Vec2& a, const Vec2& b)
{
	return std::abs(atan2(b.y, b.x) - atan2(a.y, a.x));
}

float Vec2::DotProduct(const Vec2& a, const Vec2& b)
{
	return a.x * b.x + a.y * b.y;
}

bool Vec2::IsOverlapping(const Vec2& a, const Vec2& b)
{
	return a.x <= b.y && a.y >= b.x;
}

float Vec2::CalOverlappLength(const Vec2& a, const Vec2& b)
{
	if (!Vec2::IsOverlapping(a, b))
		return 0.0f;
	else
		return std::min(a.y, b.y) - std::max(a.x, b.x);
}

} // namespace Alice
